package com.disdr;




import com.fasterxml.jackson.annotation.JsonFormat;
import java.text.ParseException;
import java.util.*;

public class json转化效率检测 {

    public static void main(String[] args) throws ParseException {

        Long start = System.currentTimeMillis();

        for(int i =0; i<10000; i++){
            String js = "{\"dateTime\":\"2024-09-14 00:00:01\",\"code\":200,\"msg\":\"操作成功\",\"requestId\":\"\",\"result\":false,\"requestURI\":\"/openapi/humanPackage/uidIsInPackage\",\"remoteHost\":\"47.99.190.141\",\"headerParam\":{\"content-length\":\"61\",\"x-traceid\":\"\",\"remoteip\":\"47.99.190.141\",\"x-sign\":\"12e474dee300a064c27e62cd88cc05b8\",\"host\":\"wedata.gymcity.com.cn\",\"x-appkey\":\"10067615200\",\"connection\":\"close\",\"content-type\":\"application/json\",\"x-forwarded-for\":\"47.99.190.141\",\"user-agent\":\"GuzzleHttp/6.5.5 curl/7.29.0 PHP/7.2.6\"},\"requestBody\":\"{\\\"packageIdList\\\":[\\\"2\\\"],\\\"ucenterId\\\":\\\"243316\\\",\\\"businessLine\\\":1}\",\"localHost\":\"172.22.233.22\",\"useTime\":28}";

            /*Pattern pattern1 = Pattern.compile("dateTime.{1,22}");
            Matcher matcher1 = pattern1.matcher(js);
            matcher1.find();
            matcher1.group();

            Pattern pattern2 = Pattern.compile("requestURI.+\",\"remoteHost\":");
            Matcher matcher2 = pattern2.matcher(js);
            matcher2.find();
            matcher2.group();

            Pattern pattern3 = Pattern.compile("useTime\":\\d+");
            Matcher matcher3 = pattern3.matcher(js);
            matcher3.find();
            matcher3.group();*/
            //10,36,95,396

            String ss = js.substring(13,32);
            ss = ss.replace("-","").replace(" ","").substring(0,10);
            //Date dateTime = DateUtil.parse(ss, DatePattern.NORM_DATETIME_FORMAT);
            String apiKey = js.substring(js.indexOf("\"requestURI\":\"") + 14 , js.indexOf("\",\"remoteHost\""));
            Long useTime = Long.valueOf(js.substring(js.lastIndexOf("\"useTime\":")+10 , js.length()-1));
            //65,66,126,284

            //JSONObject jsonObject = new JSONObject(js);
            //183,171,320,856
            //RequestLog requestLog = jsonObject.toBean(RequestLog.class);
            //430,560,1109,2844

        }

        System.out.println(System.currentTimeMillis() - start);
    }

    class RequestLog{

        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private Date dateTime;
        private int code;

        private String msg;

        private String requestId;

        private Object result;

        private String requestURI;
        private String remoteHost;
        private Map<String, Object> headerParam;
        private Map<String, String[]> requestParam;
        private  String requestBody;
        private String localHost;

        private Long useTime;//接口耗时

        public Date getDateTime() {
            return dateTime;
        }

        public void setDateTime(Date dateTime) {
            this.dateTime = dateTime;
        }

        public String getRequestId() {
            return requestId;
        }

        public void setRequestId(String requestId) {
            this.requestId = requestId;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        public Object getResult() {
            return result;
        }

        public void setResult(Object result) {
            this.result = result;
        }

        public String getRequestURI() {
            return requestURI;
        }

        public void setRequestURI(String requestURI) {
            this.requestURI = requestURI;
        }

        public String getRemoteHost() {
            return remoteHost;
        }

        public void setRemoteHost(String remoteHost) {
            this.remoteHost = remoteHost;
        }

        public Map<String, Object> getHeaderParam() {
            return headerParam;
        }

        public void setHeaderParam(Map<String, Object> headerParam) {
            this.headerParam = headerParam;
        }

        public Map<String, String[]> getRequestParam() {
            return requestParam;
        }

        public void setRequestParam(Map<String, String[]> requestParam) {
            this.requestParam = requestParam;
        }

        public String getRequestBody() {
            return requestBody;
        }

        public void setRequestBody(String requestBody) {
            this.requestBody = requestBody;
        }

        public String getLocalHost() {
            return localHost;
        }

        public void setLocalHost(String localHost) {
            this.localHost = localHost;
        }

        public Long getUseTime() {
            return useTime;
        }

        public void setUseTime(Long useTime) {
            this.useTime = useTime;
        }
    }
}


